﻿/* EntitiesToDTOs. Copyright (c) 2011. Fabian Fernandez.
 * http://entitiestodtos.codeplex.com
 * Licensed by Common Development and Distribution License (CDDL).
 * http://entitiestodtos.codeplex.com/license
 * Fabian Fernandez. 
 * http://www.linkedin.com/in/fabianfernandezb/en
 * */
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using EnvDTE;
using System.Xml.Linq;
using EntitiesToDTOs.Enums;
using EntitiesToDTOs.Properties;

namespace EntitiesToDTOs.Generators.Parameters
{
    /// <summary>
    /// Parameters for the DTOGenerator GenerateDTOs method.
    /// This is because it is used with BackgroundWorker, we need an object to provide all typed parameters.
    /// </summary>
    internal class GenerateDTOsParams
    {
        /// <summary>
        /// Project where the DTOs are going to be generated.
        /// </summary>
        public Project TargetProject { get; set; }

        /// <summary>
        /// [Used only for configuration management] 
        /// Name of the Project where the DTOs are going to be generated.
        /// </summary>
        public string TargetProjectName { get; set; }

        /// <summary>
        /// EDMX Document ProjectItem containing the Entities definitions.
        /// </summary>
        public ProjectItem EDMXProjectItem { get; set; }

        /// <summary>
        /// [Used only for configuration management] 
        /// Name of the EDMX containing the Entities definitions.
        /// </summary>
        public string EDMXName { get; set; }

        /// <summary>
        /// EDMX Document containing the Entities definitions.
        /// </summary>
        public XDocument EDMXDocument { get; set; }

        /// <summary>
        /// Source File Header Comment (optional).
        /// </summary>
        public string SourceFileHeaderComment { get; set; }

        /// <summary>
        /// Indicates if Target Project default namespace is going to be used.
        /// </summary>
        public bool UseProjectDefaultNamespace { get; set; }

        /// <summary>
        /// Namespace used for the DTOs.
        /// </summary>
        public string SourceNamespace { get; set; }

        /// <summary>
        /// Specifies if the DTOs are Service-Ready (this means if they can be serialized or not).
        /// </summary>
        public bool DTOsServiceReady { get; set; }

        /// <summary>
        /// Specifies the Source File Generation Type desired.
        /// </summary>
        public string SourceFileGenerationType
        {
            get
            {
                return _sourceFileGenerationType;
            }
            set
            {
                SourceFileGenerationTypeEnum.Validate(value);
                _sourceFileGenerationType = value;
            }
        }
        private string _sourceFileGenerationType;

        /// <summary>
        /// Source File Name to use if the Source File Generation Type is OneSourceFile.
        /// </summary>
        public string SourceFileName { get; set; }

        /// <summary>
        /// Class Association Type desired.
        /// </summary>
        public string AssociationType
        {
            get
            {
                return _associationType;
            }
            set
            {
                AssociationTypeEnum.Validate(value);
                _associationType = value;
            }
        }
        private string _associationType;

        /// <summary>
        /// Indicates if DTO's Constructor methods should be created.
        /// </summary>
        public bool GenerateDTOConstructors { get; set; }


        public GenerateDTOsParams() { }

        /// <summary>
        /// Creates a new instance of <see cref="GenerateDTOsParams"/>.
        /// </summary>
        /// <param name="targetProject">Project where the DTOs are going to be generated.</param>
        /// <param name="edmxProjectItem">EDMX Document ProjectItem containing the Entities definitions.</param>
        /// <param name="sourceFileHeaderComment">Source File Header Comment (optional).</param>
        /// <param name="useProjectDefaultNamespace">Indicates if Target Project default namespace is going to be used.</param>
        /// <param name="sourceNamespace">Namespace used for the DTOs.</param>
        /// <param name="dtosServiceReady">Specifies if the DTOs are Service-Ready (this means if they can be serialized or not).</param>
        /// <param name="sourceFileGenerationType">Specifies the Source File Generation Type desired.</param>
        /// <param name="sourceFileName">Source File Name to use if the Source File Generation Type is OneSourceFile.</param>
        /// <param name="associationType">Class Association Type desired.</param>
        /// <param name="generateDTOConstructors">Indicates if DTO's Constructor methods should be created.</param>
        public GenerateDTOsParams(Project targetProject, ProjectItem edmxProjectItem,
            string sourceFileHeaderComment, bool useProjectDefaultNamespace, string sourceNamespace, 
            bool dtosServiceReady, string sourceFileGenerationType, string sourceFileName,
            string associationType, bool generateDTOConstructors)
        {
            this.TargetProject = targetProject;
            this.EDMXProjectItem = edmxProjectItem;

            // Get the EDMX Document as XDocument type
            string edmxFilePath = this.EDMXProjectItem.Properties.Item(Resources.ProjectItem_FullPath).Value.ToString();
            this.EDMXDocument = XDocument.Load(edmxFilePath);
            
            this.SourceFileHeaderComment = sourceFileHeaderComment;
            this.UseProjectDefaultNamespace = useProjectDefaultNamespace;
            this.SourceNamespace = sourceNamespace;
            this.DTOsServiceReady = dtosServiceReady;
            this.SourceFileGenerationType = sourceFileGenerationType;
            this.SourceFileName = sourceFileName;
            this.AssociationType = associationType;
            this.GenerateDTOConstructors = generateDTOConstructors;
        }
    }
}